/*
 * Grafo.java
 *
 * 
 */
package it.luigiarpino.alt2jsim.core;

import it.luigiarpino.alt2jsim.network.FlatNet;
import it.luigiarpino.alt2jsim.network.N_Level_Network;
import it.luigiarpino.alt2jsim.network.Net;
import it.luigiarpino.alt2jsim.network.TransitStubNet;


/**
 *
 * @author  Luigi Lorenzo Arpino 534/559
 */
public class Grafo {
    
    private int numOfNode;
    private int numOfArch;
    private int scale;
    private String typeOfGraph;
    private String[] nomiNodi;
    private int[][] archi;
    private int puntatoreArchi=0;
    private int[][] posizioneNodi;
    
    /**tipo di rete transit-stub*/
    public static final String TYPE_TRANSIT="transtub";
    /**tipo di rete n-livelli*/
    public static final String TYPE_NLEVEL="geo_hier";
    /**tipo di rete flat*/
    public static final String TYPE_FLAT="geo";
    
    /** Creates a new instance of Grafo */
    public Grafo(int numOfNode_,int numOfArch_, int scale_, String typeOfGraph_) {
        this.numOfNode=numOfNode_;
        this.numOfArch=numOfArch_;
        this.scale=scale_;
        this.typeOfGraph=typeOfGraph_;
        this.nomiNodi=new String[this.numOfNode];
        this.archi=new int[this.numOfArch][3];
        this.posizioneNodi=new int[this.numOfNode][2];
    }
    
    /** Assegna il nome al nodo numero id_ */
    public void setNameOfNode(String name_ ,int id_){
        this.nomiNodi[id_]=name_;
    }
    
    /** Assegna le coordinate al nodo numeo id_ */ 
    public void setPositionOfNode(int id_, int xPos_, int yPos_){
        this.posizioneNodi[id_][0]=xPos_;
        this.posizioneNodi[id_][1]=yPos_;
    }
    
    /** Restituisce il nome del nodo numero id_*/
    public String getNameOfNode(int id_){
        return this.nomiNodi[id_];
    }
    
    /** Restituisce la lunghezza del link numero number_ */
    public int getLenghtOfLink(int number_){
        return this.archi[number_][2];
    }
    
    
    public int getSourceNodeOfLink(int number_){
        return this.archi[number_][0];
    }
    
    public int getDestNodeOfLink(int number_){
        return this.archi[number_][1];
    }
    
    public int getNumOfNode(){
        return this.numOfNode;
    }
    
    public int getNumOfLink(){
        return this.numOfArch;
    }
    

    public int getGradoOfNode(int index)
    {
    	int grado=0;
    	for(int i=0; i<numOfArch/2; i++)
    	{
    		if ( ( archi[i][0] == index) ||( archi[i][1]== index))
    		{
    			grado ++;
    		}
    	}
    	return grado;
    }
    
    public int getScale(){
        return this.scale;
    }
    
    public void addArch(int fromNode_ , int toNode_ , int lenght_){
        this.archi[this.puntatoreArchi][0]=fromNode_;
        this.archi[this.puntatoreArchi][1]=toNode_;
        this.archi[this.puntatoreArchi][2]=lenght_;
        this.puntatoreArchi=this.puntatoreArchi+1;
    }
    
    public String getTypeOfGraph(){
        return this.typeOfGraph;
    }
    
    public Net getNet(){
        if (this.typeOfGraph.equalsIgnoreCase("geo_hier")){
            N_Level_Network network=new N_Level_Network(this.numOfNode,this.numOfArch,this.scale,this.nomiNodi,this.archi , this.posizioneNodi);
            return network;
        }
        else if (this.typeOfGraph.equalsIgnoreCase("transtub")){
            TransitStubNet network=new TransitStubNet(this.numOfNode,this.numOfArch,this.scale,this.nomiNodi,this.archi,this.posizioneNodi);
            return network;
        }
        else{
            FlatNet network=new FlatNet(this.numOfNode,this.numOfArch,this.scale,this.nomiNodi,this.archi,this.posizioneNodi);
            return network;
        }
    }
    
    
}
